(1) Points that coincide with a polygon vertex are now inside the polygon by fiat...
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 17 Mar 2004 15:24:30 +0000 (15:24 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 17 Mar 2004 15:24:30 +0000 (15:24 +0000)
gpsbabel/polygon.c

index da35b76830d9368a5f05d14b104abd80331fd21e..3835f7de0dbc66400e4bd6e331b91bf0fd5c4571 100644 (file)
@@ -38,6 +38,7 @@ static char *exclopt = NULL;
 
 typedef struct {
        unsigned short state;
+       unsigned short override;
 } extra_data;
 
 static
@@ -163,7 +164,7 @@ static void polytest ( double lat1, double lon1,
                }
                else if (!(lon1 <= lon3 && lon2 <= lon3)) {
                    /* we're inside the bbox of a diagonal line.  math time. */
-                   double loni = (lon2-lon1)/(lat2-lat1)*(lat3-lat1);
+                   double loni = lon1+(lon2-lon1)/(lat2-lat1)*(lat3-lat1);
                    if ( loni > lon3 ) {
                        *state = *state ^ INSIDE;
                    }
@@ -221,8 +222,13 @@ polygon_process(void)
                else {
                    ed = xcalloc(1, sizeof(*ed));
                    ed->state = OUTSIDE;
+                   ed->override = 0;
                    waypointp->extra_data = ed;
                }
+               if ( lat2 == waypointp->latitude && 
+                    lon2 == waypointp->longitude ) {
+                   ed->override = 1;
+               }
                if ( olat != BADVAL && olon != BADVAL &&
                    olat == lat2 && olon == lon2 ) {
                    last = 1;
@@ -263,6 +269,7 @@ polygon_process(void)
                ed = wp->extra_data;
                wp->extra_data = NULL;
                if ( ed ) {
+                   if ( ed->override ) ed->state = INSIDE;
                    if (((ed->state & INSIDE) == OUTSIDE ) == (exclopt == NULL)) {
                        waypt_del(wp);
                        waypt_free(wp);